<?php
/**
 * 首页控制器
 */
class IndexController extends CommonController{
	/**
	 * 默认显示首页
	 */
	public function index(){
		//如果缓存失效了******
		if(!$this->is_cached()){
			//处理分类
			$cateData = M()->query("SELECT * FROM hd_category WHERE pid=0");
			//处理压入子集
			foreach ($cateData as $k => $v) {
				$cateData[$k]['son'] = M()->query("SELECT * FROM hd_category WHERE pid={$v['cid']}");
			}
	        //p($cateData);die;
			$this->assign('cateData',$cateData);
			$this->topCate();
			//处理待解决的问题
			$noSolve = M()->query("SELECT * FROM hd_ask WHERE solve=0");
			$this->assign('noSolve',$noSolve);
			//高分悬赏的问题
			$noReward = M()->query("SELECT * FROM hd_ask WHERE reward>1 and answer=0 order by reward desc");
			$this->assign('noReward',$noReward);
			//后盾问答助人光荣榜
			$noAccept = M()->query("SELECT * FROM hd_user order by accept desc");
			$this->assign('noAccept',$noAccept);
			//历史回答问题最多的人
			$noAnswer = M()->query("SELECT * FROM hd_user order by answer desc limit 1");
			$this->assign('noAnswer',$noAnswer);
			//本日回答问题最多的人
			$zero =  strtotime(date('Y-m-d'));
			
            $sql = "select u.uid,u.username,count(*) as c from hd_answer as a inner join hd_user as u on a.uid=u.uid where time >{$zero} group by uid order by c desc limit 1";
			$noToday = M()->query($sql);
			
			
			$this->assign('noToday',$noToday);
		}
		
		
		
		
		
		$this->display();
	}
}

?>